home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / DNet / DTCP.h < prev    next >
Text File  |  1996-07-05  |  5KB  |  152 lines

  1. // DTCP.h  
  2. // by D. Gilbert, 1991-92, with help from code of Harry Chesley, Peter Speck and others 
  3.  
  4. #ifndef __DTCP__
  5. #define __DTCP__
  6.  
  7. #include <DObject.h>
  8.  
  9. class DTaskMaster;
  10.  
  11.  
  12. extern "C" {
  13. typedef  Boolean  (*TCPUserBreakHandler)(DTaskMaster* /* itsObject */);        
  14. typedef  void  (*TCPMessageHandler)(DTaskMaster* , long , const char* ); /* itsObject, msgID, msg */
  15. }
  16.  
  17.  
  18. enum NetChars { kCR = '\015', kLF = '\012' };
  19.  
  20.  
  21. class    DTCP : public DObject {
  22. public:                
  23.         enum TCPlineEndFlags { kDontAddCRLF= false, kAddCRLF = true};
  24.         enum TCPSendFlags { kDontSendNow= false, kSendNow = true};
  25.     
  26.         enum TCPStatusResults { kTCPreleased = -1, kTCPclosed = 0,
  27.             kTCPlistening = 2, kTCPopening = 4, kTCPestablished = 8,
  28.             kTCPclosing = 16, kTCPPleaseClose = 14, kTCPUnknownState = 32,
  29.             kTCPwaitingforopen = 64};
  30.             
  31.         enum TCPExpectedBytesFlags { kTCPStopAtdotcrlf = -1, kTCPStopAtclose = -2};
  32.         
  33.         
  34.         DTCP();
  35.         virtual ~DTCP();
  36.         virtual void Initialize();
  37.  
  38.         virtual Boolean IsTCPInstalled();
  39.         
  40.         virtual void Fail(long errNo);
  41.         virtual void Fail(const char* msg);
  42.         virtual Boolean Failed();    // ???
  43.  
  44.         virtual long        Status();
  45.         virtual char*         StatusString(short state);  
  46.         virtual long        Version();  
  47.         virtual const char*    VersionString();  //??
  48.         
  49.         virtual void InstallMessageHandler(TCPMessageHandler aproc, DTaskMaster* itsObject);
  50.         virtual void InstallUserBreak(TCPUserBreakHandler aproc, DTaskMaster* itsObject);
  51.  
  52.         virtual void ShowMessage(const char* msg);
  53.         virtual void StatusMessage();
  54.         virtual void SetShowProgress( Boolean turnOn);
  55.         virtual void ShowProgress( long sendRecvCount);
  56.         virtual void ShowProgress();
  57.         
  58.         virtual Boolean EndOfMessage();
  59.         virtual void    SetEndOfMessage( Boolean isEnded);
  60.         
  61.         virtual Boolean UserBreak();
  62.         virtual void StreamYieldTime(); // makes TCPAbort if aborted from TThread
  63.  
  64.         virtual long NameToAddress(const char* hostName);
  65.         virtual char* AddressToName(long address);
  66.         virtual char* DotAddrToName(const char* dotAddress);
  67.         virtual char* RemoteName();
  68.  
  69.         void Open( char* hostname, unsigned short hostport, unsigned short localport = 0);
  70.         //void Open(long hostIP, unsigned short hostport, unsigned short localport = 0);
  71.  
  72.         virtual Boolean WaitedForOpen(long delayticks);
  73.         virtual Boolean WaitedForOpen();
  74.         virtual void Close();
  75.         virtual void Release();
  76.         virtual void Abort(); 
  77.  
  78.         virtual void SendBytes(void *data, long datasize, Boolean immediately = true);
  79.         virtual void Send(char *cstring, Boolean immediately = true);
  80.         virtual void SendCRLF( Boolean EvenIfLastSendHadCRLF = true, Boolean immediately = true);
  81.         virtual void SendStr( char* s, Boolean addCRLF = true, Boolean immediately = true);
  82.  
  83.         virtual long CharsAvailable();
  84.         virtual long TotalBytesReceived(); //??
  85.         virtual long NewBytesReceived();     //??
  86.         virtual long ConnectTime();
  87.         virtual    void NullTerm( Boolean turnon = true);
  88.         virtual void EatResponseLine();
  89.         
  90.         virtual short ReceiveData( void *data, long datasize, long &bytesReceived,
  91.                             Boolean stopatlf = false);  
  92.         virtual char* ReadWithChecks( ulong& bufsize, long expectedbytes = kTCPStopAtclose, 
  93.                             Boolean convertnewline = false, long maxbytes = 0, char* oldbuffer = NULL);
  94.         virtual short RecvByte();  
  95.         virtual char* RecvLine(); // read up to first LF
  96.         virtual char* RecvChars( long readCount, long& numread);
  97. #if NOT_USEFUL
  98.         virtual char* RecvChunk( long maxChunk= 0, char* oldChunk= NULL);
  99. #endif
  100.  
  101.  
  102. protected:
  103.         long            fSocket;                    // socket descriptor
  104.         long            fTimeout;    
  105.         Boolean        fFailed;                  // last op failed if true
  106.         char*            fError;                     // change to number...
  107.         long            fErrNo;
  108.         Boolean        fDoShowProgress;  // if true, ShowProgress 
  109.         Boolean        fEndofMessage;        // true if recv found end-of-message (dot-cr-lf) 
  110.  
  111.         long            fBytesread;    
  112.         long            fResultSize;            // we don't need all of these counters !!
  113.         long            fResultNew;
  114.         long            fResultTotal;
  115.         long            fMaxResultSize; 
  116.         long            fLimitResultSize;     // recv buffer ptrs 
  117.         char*            fResultHand;                // recv buffer 
  118.         long            fStartTime;                    // time at open connection
  119.         long            fConnectTime;                // == current or close time - start time
  120.         
  121.         TCPMessageHandler fMessageProc;
  122.         DTaskMaster*    fMessageObj;
  123.         TCPUserBreakHandler fBreakProc;
  124.         DTaskMaster*    fBreakObj;
  125.  
  126.         Boolean        fLastSentCRLF;    // last send ended w/ crlf
  127.         Boolean        fNullTerm;
  128.         
  129. private: 
  130. // from TMacTCP..............
  131.         Boolean fConnectionIsOpen;
  132.         Boolean fStreamIsOpen;
  133.         char        fLastc,fLast2c,fLast3c;
  134.         long        fReadSaveLen;
  135.         char*        fReadSaveBase;
  136.         char*        fReadSave;
  137.  
  138. };
  139.         
  140.         
  141. extern    long    gTCPTimeout;        // value for fTimeout for each new TTCP
  142.  
  143. Boolean TCPIsItInstalled();
  144. long          MyIP();
  145. char*     GetMyDotName();
  146. long       DotName2IP(const char* name);
  147. char*     IP2DotName(long ip);    // this one currently is broken
  148.  
  149.  
  150. #endif
  151.  
  152.